'''
Created on Sep 17, 2009

@author: Devin
'''
import cmd, sys
from shotcuts import Shotcuts

class ShotcutManage(cmd.Cmd):
    '''
    classdocs
    '''

    def __init__(self, shotcuts):
        cmd.Cmd.__init__(self)
        self.prompt='shotcuts>'
        self.shotcuts = shotcuts
        '''
        Constructor
        '''
        
    def help_exit(self):
        print 'exit shotcut config'
        
    def do_exit(self, line):
        return True
    
            
    def help_add(self):
        tip =   '''add a new shotcut
        usage: add [shotcutname]'''
        print tip
    
    def do_add(self, sc):
        if sc =="":
            sc = raw_input('Please input the shotcut: ')
        if self.shotcuts.add(sc):
            print 'add shotcut successful, current shotcuts:'
            self.shotcuts.save()
        else:
            print 'the shotcut has already exists'
        self.shotcuts.printall()
        
    def help_show(self):
        print 'show all shotcuts'
        
    def do_show(self, line):
        self.shotcuts.printall()